home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Text / Show / Less / less-252 / opttbl.c < prev    next >
C/C++ Source or Header  |  1994-10-27  |  7KB  |  279 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994  Mark Nudelman
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice in the documentation and/or other materials provided with 
  12.  *    the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
  15.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  17.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
  18.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
  20.  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
  21.  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  22.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
  23.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
  24.  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26.  
  27.  
  28. /*
  29.  * The option table.
  30.  */
  31.  
  32. #include "less.h"
  33. #include "option.h"
  34.  
  35. /*
  36.  * Variables controlled by command line options.
  37.  */
  38. public int quiet;        /* Should we suppress the audible bell? */
  39. public int how_search;        /* Where should forward searches start? */
  40. public int top_scroll;        /* Repaint screen from top?
  41.                    (alternative is scroll from bottom) */
  42. public int pr_type;        /* Type of prompt (short, medium, long) */
  43. public int bs_mode;        /* How to process backspaces */
  44. public int know_dumb;        /* Don't complain about dumb terminals */
  45. public int quit_at_eof;        /* Quit after hitting end of file twice */
  46. public int squeeze;        /* Squeeze multiple blank lines into one */
  47. public int tabstop;        /* Tab settings */
  48. public int back_scroll;        /* Repaint screen on backwards movement */
  49. public int forw_scroll;        /* Repaint screen on forward movement */
  50. public int twiddle;        /* Display "~" for lines after EOF */
  51. public int caseless;        /* Do "caseless" searches */
  52. public int linenums;        /* Use line numbers */
  53. public int cbufs;        /* Current number of buffers */
  54. public int autobuf;        /* Automatically allocate buffers as needed */
  55. public int nohelp;        /* Disable the HELP command */
  56. public int ctldisp;        /* Send control chars to screen untranslated */
  57. public int force_open;        /* Open the file even if not regular file */
  58. public int swindow;        /* Size of scrolling window */
  59. public int jump_sline;        /* Screen line of "jump target" */
  60. public int chopline;        /* Truncate displayed lines at screen width */
  61. public int no_init;        /* Disable sending ti/te termcap strings */
  62. #if HILITE_SEARCH
  63. public int hilite_search;    /* Highlight matched search patterns? */
  64. #endif
  65.  
  66. /*
  67.  * Table of all options and their semantics.
  68.  */
  69. static struct option option[] =
  70. {
  71.     { 'a', BOOL, 0, &how_search, NULL,
  72.         "Search includes displayed screen",
  73.         "Search skips displayed screen",
  74.         NULL
  75.     },
  76.     { 'b', NUMBER, 10, &cbufs, opt_b, 
  77.         "Buffers: ",
  78.         "%d buffers",
  79.         NULL
  80.     },
  81.     { 'B', BOOL, 1, &autobuf, NULL,
  82.         "Don't automatically allocate buffers",
  83.         "Automatically allocate buffers when needed",
  84.         NULL
  85.     },
  86.     { 'c', TRIPLE, 0, &top_scroll, NULL,
  87.         "Repaint by scrolling from bottom of screen",
  88.         "Repaint by clearing each line",
  89.         "Repaint by painting from top of screen"
  90.     },
  91.     { 'd', BOOL|NO_TOGGLE, 0, &know_dumb, NULL,
  92.         "Assume intelligent terminal",
  93.         "Assume dumb terminal",
  94.         NULL
  95.     },
  96. #if MSOFTC
  97.     { 'D', STRING|REPAINT, 0, NULL, opt_D,
  98.         "color desc: ", NULL, NULL
  99.     },
  100. #endif
  101.     { 'e', TRIPLE, 0, &quit_at_eof, NULL,
  102.         "Don't quit at end-of-file",
  103.         "Quit at end-of-file",
  104.         "Quit immediately at end-of-file"
  105.     },
  106.     { 'f', BOOL, 0, &force_open, NULL,
  107.         "Open only regular files",
  108.         "Open even non-regular files",
  109.         NULL
  110.     },
  111. #if HILITE_SEARCH
  112.     { 'F', BOOL|REPAINT, 1, &hilite_search, NULL,
  113.         "Don't highlight matches for previous search pattern",
  114.         "Highlight all matches for previous search pattern",
  115.         NULL
  116.     },
  117. #endif
  118.     { 'h', NUMBER, -1, &back_scroll, NULL,
  119.         "Backwards scroll limit: ",
  120.         "Backwards scroll limit is %d lines",
  121.         NULL
  122.     },
  123.     { 'H', BOOL|NO_TOGGLE, 0, &nohelp, NULL,
  124.         "Allow help command",
  125.         "Don't allow help command",
  126.         NULL
  127.     },
  128.     { 'i', BOOL|REPAINT, 0, &caseless, opt_i,
  129.         "Case is significant in searches",
  130.         "Ignore case in searches",
  131.         NULL
  132.     },
  133.     { 'j', NUMBER, 1, &jump_sline, NULL,
  134.         "Target line: ",
  135.         "Position target at screen line %d",
  136.         NULL
  137.     },
  138. #if USERFILE
  139.     { 'k', STRING|NO_TOGGLE, 0, NULL, opt_k,
  140.         NULL, NULL, NULL
  141.     },
  142. #endif
  143. #if LOGFILE
  144.     { 'l', STRING|NO_TOGGLE, 0, NULL, opt_l,
  145.         NULL, NULL, NULL
  146.     },
  147.     { 'L', STRING, 0, NULL, opt__L,
  148.         NULL, NULL, NULL
  149.     },
  150. #endif
  151.     { 'm', TRIPLE, 0, &pr_type, NULL,
  152.         "Short prompt",
  153.         "Medium prompt",
  154.         "Long prompt"
  155.     },
  156.     { 'n', TRIPLE|REPAINT, 1, &linenums, NULL,
  157.         "Don't use line numbers",
  158.         "Use line numbers",
  159.         "Constantly display line numbers"
  160.     },
  161. #if LOGFILE
  162.     { 'o', STRING, 0, NULL, opt_o,
  163.         "log file: ", NULL, NULL
  164.     },
  165.     { 'O', STRING, 0, NULL, opt__O,
  166.         "Log file: ", NULL, NULL
  167.     },
  168. #endif
  169.     { 'p', STRING|NO_TOGGLE, 0, NULL, opt_p,
  170.         NULL, NULL, NULL
  171.     },
  172.     { 'P', STRING, 0, NULL, opt__P,
  173.         "prompt: ", NULL, NULL
  174.     },
  175.     { 'q', TRIPLE, 0, &quiet, NULL,
  176.         "Ring the bell for errors AND at eof/bof",
  177.         "Ring the bell for errors but not at eof/bof",
  178.         "Never ring the bell"
  179.     },
  180.     { 'r', BOOL|REPAINT, 1, &ctldisp, NULL,
  181.         "Display control characters directly",
  182.         "Display control characters as ^X",
  183.         NULL
  184.     },
  185.     { 's', BOOL|REPAINT, 0, &squeeze, NULL,
  186.         "Display all blank lines",
  187.         "Squeeze multiple blank lines",
  188.         NULL
  189.     },
  190.     { 'S', BOOL|REPAINT, 0, &chopline, NULL,
  191.         "Fold long lines",
  192.         "Chop long lines",
  193.         NULL
  194.     },
  195. #if TAGS
  196.     { 't', STRING, 0, NULL, opt_t,
  197.         "tag: ", NULL, NULL
  198.     },
  199.     { 'T', STRING, 0, NULL, opt__T,
  200.         "tags file: ", NULL, NULL
  201.     },
  202. #endif
  203.     { 'u', TRIPLE|REPAINT, 0, &bs_mode, NULL,
  204.         "Display underlined text in underline mode",
  205.         "Backspaces cause overstrike",
  206.         "Print backspace as ^H"
  207.     },
  208.     { 'V', NOVAR, 0, NULL, opt__V,
  209.         NULL, NULL, NULL
  210.     },
  211.     { 'w', BOOL|REPAINT, 1, &twiddle, NULL,
  212.         "Display nothing for lines after end-of-file",
  213.         "Display ~ for lines after end-of-file",
  214.         NULL
  215.     },
  216.     { 'x', NUMBER|REPAINT, 8, &tabstop, NULL,
  217.         "Tab stops: ",
  218.         "Tab stops every %d spaces", 
  219.         NULL
  220.     },
  221.     { 'X', BOOL|NO_TOGGLE, 0, &no_init, NULL,
  222.         "Send init/deinit strings to terminal",
  223.         "Don't use init/deinit strings",
  224.         NULL
  225.     },
  226.     { 'y', NUMBER, -1, &forw_scroll, NULL,
  227.         "Forward scroll limit: ",
  228.         "Forward scroll limit is %d lines",
  229.         NULL
  230.     },
  231.     { 'z', NUMBER, -1, &swindow, NULL,
  232.         "Scroll window size: ",
  233.         "Scroll window size is %d lines",
  234.         NULL
  235.     },
  236.     { '?', NOVAR, 0, NULL, opt_query,
  237.         NULL, NULL, NULL
  238.     },
  239.     { '\0' }
  240. };
  241.  
  242.  
  243. /*
  244.  * Initialize each option to its default value.
  245.  */
  246.     public void
  247. init_option()
  248. {
  249.     register struct option *o;
  250.  
  251.     for (o = option;  o->oletter != '\0';  o++)
  252.     {
  253.         /*
  254.          * Set each variable to its default.
  255.          */
  256.         if (o->ovar != NULL)
  257.             *(o->ovar) = o->odefault;
  258.     }
  259. }
  260.  
  261. /*
  262.  * Find an option in the option table.
  263.  */
  264.     public struct option *
  265. findopt(c)
  266.     int c;
  267. {
  268.     register struct option *o;
  269.  
  270.     for (o = option;  o->oletter != '\0';  o++)
  271.     {
  272.         if (o->oletter == c)
  273.             return (o);
  274.         if ((o->otype & TRIPLE) && toupper(o->oletter) == c)
  275.             return (o);
  276.     }
  277.     return (NULL);
  278. }
  279.